//
//  CardCenterCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/9/10.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class CardCenterCell: UITableViewCell {

    let titleImageView = UIImageView()
    let titleLabel = UILabel()
    let newLabel = UILabel()
    let numberLabel = UILabel()
    let requestBtn = UIButton()
    
    var model : CardCenterModel!{
        
        didSet{
            updateData()
        }
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        self.contentView.backgroundColor = UIColor.white
        
        self.contentView.addSubview(titleImageView)
        
        titleLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.contentView.addSubview(titleLabel)
        
        newLabel.textColor = UIColor.lightGray
        newLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.contentView.addSubview(newLabel)
        
        numberLabel.textColor = UIColor.red
        numberLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.contentView.addSubview(numberLabel)
        
        let personLabel = UILabel()
        personLabel.text = peopleForApplication
        personLabel.textColor = UIColor.lightGray
        personLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.contentView.addSubview(personLabel)
        
        requestBtn.setTitle(freeApplication, for: .normal)
        requestBtn.backgroundColor = UIColor.pinkColor()
        requestBtn.setTitleColor(UIColor.white, for: .normal)
        requestBtn.titleLabel?.font = UIFont.systemFont(ofSize: RATIO(maxNum: 14))
        self.contentView.addSubview(requestBtn)
        
        let lineView = UIView()
        lineView.backgroundColor = UIColor.lineColor()
        self.contentView.addSubview(lineView)
        
        titleImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.height.equalTo(RATIO_H(maxNum: 80))
            make.width.equalTo(RATIO(maxNum: 120))
        }
        
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleImageView.snp.right).offset(RATIO(maxNum: 8))
            make.right.equalToSuperview().offset(RATIO(maxNum: -8))
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.height.equalTo(RATIO_H(maxNum: 20))
        }
        
        newLabel.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel)
            make.right.equalTo(titleLabel)
            make.top.equalTo(titleLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.height.equalTo(titleLabel)
        }
        
        numberLabel.snp.makeConstraints { (make) in
            make.left.equalTo(newLabel)
            make.width.greaterThanOrEqualTo(10)
            make.top.equalTo(newLabel.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.height.equalTo(newLabel)
        }
        
        personLabel.snp.makeConstraints { (make) in
            make.left.equalTo(numberLabel.snp.right)
            make.top.equalTo(numberLabel)
            make.height.equalTo(numberLabel)
            make.width.greaterThanOrEqualTo(10)
        }
        
        requestBtn.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(RATIO(maxNum: 8))
            make.right.equalToSuperview().offset(RATIO(maxNum: -8))
            make.top.equalTo(titleImageView.snp.bottom).offset(RATIO_H(maxNum: 10))
            make.height.equalTo(RATIO_H(maxNum: 30))
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    //MARK: 刷新数据
    fileprivate func updateData() {
        
        titleImageView.setUrlImage(with: kmHttps + model.image!, placeholder: UIImage.imageWithName("loading"))
        titleLabel.text = model.credit_name!
        newLabel.text = model.favorable
        numberLabel.text = model.num
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }


}
